// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: calendar.cpp 227 2008-09-15 13:33:40Z heavyzheng $
//

#ifndef ZZHENG_QUANT_DATES_SOURCE
#define ZZHENG_QUANT_DATES_SOURCE
#endif // ZZHENG_QUANT_DATES_SOURCE

#include <zzheng/quant/dates/calendar.hpp>
#include <zzheng/quant/dates/date.hpp>
#include <string>
#include <algorithm>

namespace zzheng {
namespace quant {
namespace dates {

    calendar::calendar(const std::string& center): center_(center), weekends_(), holidays_() {
        weekends_.push_back(date::saturday);
        weekends_.push_back(date::sunday);
    }

    const std::string& calendar::center() const {
        return center_;
    }

    bool calendar::is_business_day(const date& d) const {
        return (!is_weekend(d) && !is_holiday(d));
    }

    bool calendar::is_weekend(const date& d) const {
        return ( std::find(weekends_.begin(), weekends_.end(), d.weekday()) != weekends_.end() );
    }

    bool calendar::is_holiday(const date& d) const {
        month_day_pair month_day = std::make_pair(d.month(), d.day());
        return ( std::find(holidays_.begin(), holidays_.end(), month_day) != holidays_.end() );
    }

    void calendar::add_weekend(date::weekday_type weekend) {
        weekends_.push_back(weekend);
    }

    void calendar::clear_weekends() {
        weekends_.clear();
    }

    void calendar::add_holiday(date::month_type month, date::day_type day) {
        holidays_.push_back(std::make_pair(month, day));
    }

    void calendar::clear_holidays() {
        holidays_.clear();
    }

} // namespace zzheng::quant::dates
} // namespace zzheng::quant
} // namespace zzheng



